<template>
  <div class="wechats-list scroll">
    <span class="tips">所在微信</span>
    <el-select
      class="el-select-wechats-list"
      v-model="currentWechat"
      size="small"
      clearable
      placeholder="请选择微信"
      @change="queryInfoByWechatId($event)"
    >
      <el-option
        v-for="(wechat, index) in wechats"
        :key="index"
        :label="wechat.WeChatNick"
        :value="wechat.WeChatId"
        :disabled="!wechat.IsOnline || !wechat.IsLogined"
      ></el-option>
    </el-select>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'WechatsList',
  data() {
    return {
    }
  },
  computed: {
    ...mapGetters({
      currentNavs: 'currentNavs',
      wechats: 'conversation/wechats',
      currentWechats: 'currentWechats',
    }),
    currentNav() {
      return this.currentNavs[this.$route.name]
    },
    currentWechat: {
      get() {
        return this.currentWechats[this.currentNav]
      },
      set(v) {
        this.$store.commit('SET_CURRENT_WECHATS', v)
      }
    }
  },
  methods: {
    // 根据微信id查询数据
    queryInfoByWechatId(wechatId) {
      // if (!wechatId) return
      this.$store.commit('SET_CURRENT_WECHATS', wechatId)
      switch (this.currentNav) {
        case 'newFriend':
          // 从nedb查询%s的新的朋友列表'
          this.$store.dispatch('nedb/SetNewFriends', wechatId)
          break;
        case 'addFriend':
          // 从nedb查询%s的添加好友的历史任务列表'
          this.$store.dispatch('nedb/SetAddFriends', wechatId)
          break;
        case 'clearFans':
          // 从nedb查询%s的清理僵尸粉任务列表'
          this.$store.dispatch('nedb/SetZombies', wechatId)
          break;
        case 'qrCode':
          // 从nedb查询%s的二维码'
          this.$store.dispatch('nedb/SetQrCode', wechatId)
          break;
        case 'autoReply':
          this.$message({
            message: '自动回复 的设置对所有的微信生效,无需选中微信!',
            type: 'warning'
          })
          break;
        case 'autoHi':
          this.$message({
            message: '自动打招呼 的设置对所有的微信生效,无需选中微信!',
            type: 'warning'
          })
          break;
        case 'groupSend':
          this.$store.dispatch('nedb/SetGroupSendFriends', wechatId)
          this.$store.dispatch('nedb/SetGroupSendLabels', wechatId)
          break;
        case 'groupLog':
          this.$store.dispatch('nedb/SetGroupSendLog', wechatId)
          break;
        case 'circleSend':
          this.$store.dispatch('nedb/SetCircleFriends', wechatId)
          this.$store.dispatch('nedb/SetCircleLabels', wechatId)
          break;
        case 'circleMy':
          // 查询我的朋友圈
          this.$store.dispatch('nedb/SetCurrentCircles', wechatId)
          break;
        case 'circleLog':
          this.$store.dispatch('nedb/SetFriendCircleLog', wechatId)
          break;
        default:
          break;
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.wechats-list {
  padding: 5px;
  border-bottom: solid $border-color-2 2px;
  .tips {
    width: 110px;
    font-weight: 400px;
    color: $font-color-1;
    margin-right: 10px;
    display: inline-block;
    // border: solid red 1px;
  }
  //   .el-select-wechats-list {
  //     margin-left: 10px;
  //   }
}
</style>
